#include "login.h"
#include "../gateway.h"

Login::Login()
: m_state(STATE_START)
, m_nextState(STATE_LOGIN)
{
}

Login::~Login()
{
}

void Login::Update()
{
	if(m_nextState != m_state)
	{
		SetState(m_nextState);
	}
}

void Login::SetState(State state)
{
	switch(state)
	{
	case STATE_LOGIN:
		{
			BlockTree tree;
			tree.AddChild(Def::KEY_USERNAME)->SetString("username");
			tree.AddChild(Def::KEY_PASSWORD)->SetString("123456");

			NetPacket sendPacket(Def::OPCODE_CS_LOGIN, this);
			m_gateway->PushSendPacket(sendPacket, &tree);
		}
		break;

	case STATE_END:
		m_bDone = true;
		break;
	}

	m_state = state;
	m_nextState = m_state;
}

int Login::HandleLogin(NetPacket& packet)
{		
	vector<string> params; params.clear();
	m_serviceManager->CallService(SERVICE_LOGOUT, params);

	SetState(STATE_END);
	return 0;
}
